package com.mh.study.streams;

import java.util.Arrays;
import java.util.Collection;
import java.util.function.UnaryOperator;
import java.util.stream.Stream;

/**
 * @author meng.han
 * @since 2021-12-27
 */
public class StreamCreation {

    public <T> Stream<T> emptyStream() {
        return Stream.empty();
    }

    public Stream<String> streamOfCollection(Collection<String> collection) {
        return collection.stream();
    }

    public Stream<String> streamOfArrayFull(String[] array) {
        return Arrays.stream(array);
    }

    public Stream<String> streamOfArrayPart(String[] array, int startInclusive, int endExclusive) {
        return Arrays.stream(array, startInclusive, endExclusive);
    }

    public Stream<String> streamBuilder(String[] arr) {
        Stream.Builder<String> builder = Stream.<String>builder();
        for(String a : arr){
            builder.add(a);
        }
        return builder.build();
    }

    public Stream<String> generate(final String a, int limit){
        return Stream.generate(() -> a).limit(limit);
    }

    public Stream<Integer> iterate(int seed, UnaryOperator<Integer> f, int limit){
        return Stream.iterate(seed, f).limit(limit);
    }
}
